package dodo.mindmap;

import geomerative.RPoint;

import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;

import processing.core.PApplet;

public class RoundRectangle extends RoundRectangle2D.Float implements Drawable {
	
	float K = 0.5522847498307933984022516322796f;
	
	public RoundRectangle(float x, float y, float w, float h, float arc){
		//super(x+(w/2), y+(h/2), w, h, arc, arc);
		super(x,y,w,h,arc,arc);
	}
	
	public RoundRectangle(RPoint pos, RPoint size, float arc){
		//super(pos.x+(size.x/2), pos.y+(size.y/2), size.x, size.y, arc, arc);
		super(pos.x, pos.y, size.x, size.y, arc, arc);
	}
	
	public void draw(PApplet parent) {
		parent.beginShape();
		RPoint min = new RPoint((float) getMinX(), (float) getMinY());
		RPoint max = new RPoint((float) getMaxX(), (float) getMaxY());
		RPoint arc = new RPoint((float) getArcWidth(),(float) getArcHeight());
		
		parent.vertex(max.x - arc.x, min.y);
		parent.bezierVertex(max.x - (1-K)*arc.x, min.y, max.x, min.y + (1-K)*arc.y, max.x, min.y + arc.y);

		parent.vertex(max.x, max.y - arc.y);
		parent.bezierVertex(max.x, max.y - (1-K)*arc.y, max.x - (1-K)*arc.x, max.y, max.x - arc.x, max.y);

		parent.vertex(min.x + arc.x,max.y);
		parent.bezierVertex(min.x + (1-K)*arc.x, max.y, min.x, max.y - (1-K)*arc.y, min.x, max.y - arc.y);

		parent.vertex(min.x, min.y + arc.y);
		parent.bezierVertex(min.x, min.y + (1-K)*arc.y, min.x + (1-K)*arc.x, min.y, min.x + arc.x, min.y);
		
		parent.vertex(max.x - arc.x, min.y);
		parent.endShape();
	}
	
	public void setFrame(double x, double y, double w, double h){
		super.setFrame(x, y, w, h);
	}
	
	public Rectangle2D getTextBoxBounds() {
		return new Rectangle2D.Double(
				getHeight() + 2 * getArcHeight() * (PApplet.sin((float) 45) - 1),
				getWidth() + 2 * getArcWidth() * (PApplet.sin((float) 45) - 1),
				getCenterX(), getCenterY());
	}

}
